class Solution1004_2 {

    public static void main(String[] args) {
        int[] arr = {0,0,1,1,1,0,0};
        System.out.println(longestOnes(arr, 0));
    }
    public static int longestOnes(int[] nums, int k) {
        int max = 0 ;
        int left = 0 ;
        int right = 0 ;
        int len = nums.length ;
        int ret = 0 ;
        while(right < len){
            while(right < len ){
                if(nums[right] == 0) ret ++ ;
                if(ret > k) break ;
                right++ ;
            }

            max = Math.max(right-left, max) ;

            while(left <= right && ret > k){
                if(nums[left] == 0){
                    ret -- ;
                }
                left++ ;
            }
            right++ ;
        }

        return max ;
    }
}